pub fn convert_base(num_str: &str, to_base: u32) -> String {
    
    let parts: Vec<&str> = num_str.trim_end_matches(')').split('(').collect();
    let num = parts[0];
    let from_base = parts[1].parse::<u32>().unwrap();

    if from_base < 2 || from_base > 16 || to_base < 2 || to_base > 16 {
        panic!("进制必须在2-16之间");
    }

    let decimal = u32::from_str_radix(num, from_base).unwrap();
    
    match to_base {
        2..=10 => {
            let mut result = String::new();
            let mut n = decimal;
            while n > 0 {
                result.insert(0, std::char::from_digit(n % to_base, to_base).unwrap());
                n /= to_base;
            }
            if result.is_empty() {
                "0".to_string()
            } else {
                result
            }
        }
        11..=16 => {
            let mut result = String::new();
            let mut n = decimal;
            while n > 0 {
                let digit = n % to_base;
                let c = match digit {
                    0..=9 => std::char::from_digit(digit, to_base).unwrap(),
                    10..=15 => ((digit - 10) as u8 + b'a') as char,
                    _ => unreachable!()
                };
                result.insert(0, c);
                n /= to_base;
            }
            if result.is_empty() {
                "0".to_string()
            } else {
                result
            }
        }
        _ => unreachable!()
    }
}
